package job.work.controller.system;

import job.work.domain.response.CommonCode;
import job.work.domain.response.ResponseResult;
import job.work.domain.system.entity.pojo.DecRole;
import job.work.service.system.service.DecRolesService;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zzy
 * @Classname DecRoleController
 * @Date 2020/9/27 10:05
 * @Created by Administrator
 */

@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
@CrossOrigin
public class DecRoleController {


    @Resource
    DecRolesService decRolesService;

    @GetMapping("/findAllRole")
    @ApiOperation(value = "查询所有角色")
    public ResponseResult findAllRole() {
        return decRolesService.findAllRole();
    }


    @PostMapping("/saveRole")
    @ApiOperation(value = "保存或者修改角色")
    public ResponseResult saveRole(@Validated @RequestBody DecRole decRole) {
        return decRolesService.saveRole(decRole);
    }

    @DeleteMapping("/deleteRole/{id}")
    @ApiOperation(value = "根据角色ID删除角色")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "角色Id", required = true, dataType = "int", paramType = "path"),
          })
    public ResponseResult deleteRole(@PathVariable(value = "id") Long id) {
        if (id == null) {
            return new ResponseResult<>(CommonCode.PARAM_ERROR);
        }
        return decRolesService.deleteRole(id);
    }

    @GetMapping("/findLastRole")
    @ApiOperation("根据角色id查询当前角色有哪些权限 只要最后一级")
    public ResponseResult findLastRole(@ApiParam("角色id") Long roleId){
        return decRolesService.findLastRole(roleId);
    }

    @GetMapping("/findByEachRole")
    @ApiOperation("根据角色返回角色所有的权限")
    public ResponseResult findByEachRole(@ApiParam("角色id") @RequestParam(required = true) Long roleId){
        return decRolesService.findByEachRole(roleId);
    }








}
